import axios from 'axios'
import config from './config.js'

export default {
  install: function (Vue) {
    const auth = Vue.prototype.$auth
    const obj = axios.create({
      baseURL: config.baseURL
    })

    // 请求拦截器
    obj.interceptors.request.use(function (config) {
      const token = auth.getAuthorization()
      if (token) {
        config.headers.Authorization = token
      }
      return config
    }, function (error) {
      return Promise.reject(error)
    })

    Vue.prototype.$http = obj
  }
}